package com.hotel.web.controller.system;

import com.hotel.common.annotation.Log;
import com.hotel.common.core.controller.BaseController;
import com.hotel.common.core.domain.AjaxResult;
import com.hotel.common.core.page.TableDataInfo;
import com.hotel.common.enums.BusinessType;
import com.hotel.common.utils.poi.ExcelUtil;
import com.hotel.system.domain.SysPost;
import com.hotel.system.domain.hotel.HotelInventory;
import com.hotel.system.domain.hotel.HotelInventoryLog;
import com.hotel.system.service.ISysKcglService;
import com.hotel.system.service.ISysPostService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * 岗位信息操作处理
 * 
 * @author hotel
 */
@Controller
@RequestMapping("/system/kcgl")
public class SysKcglController extends BaseController
{
    private String prefix = "system/kcgl";

    @Autowired
    private ISysKcglService kcglService;

    @RequiresPermissions("system:kcgl:view")
    @GetMapping()
    public String operlog()
    {
        return prefix + "/post";
    }

//    @RequiresPermissions("system:kcgl:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(HotelInventory post)
    {

        startPage();
        List<HotelInventory> list = kcglService.selectInventoryList(post);
        System.out.println(list.toString());
        return getDataTable(list);
    }

    /**
     * 库存入库
     */
    @GetMapping("/add/{inventoryCode}")
    public String add(@PathVariable("inventoryCode") String inventoryCode, ModelMap mmap)
    {
        mmap.put("post", kcglService.selectInventoryCode(inventoryCode));
        return prefix + "/add";
    }

    /**
     * 库存出库
     */
    @GetMapping("/edit/{inventoryCode}")
    public String edit(@PathVariable("inventoryCode") String inventoryCode, ModelMap mmap)
    {
        mmap.put("post", kcglService.selectInventoryCode(inventoryCode));
        return prefix + "/edit";
    }


    /**
     * 出库入库调整
     */
    @Log(title = "出库入库", businessType = BusinessType.UPDATE)
    @PostMapping("/ckrk")
    @ResponseBody
    public AjaxResult ckrk(@Validated HotelInventory hotelInventory)
    {
        kcglService.insertHotelInventoryLog(hotelInventory);
        return toAjax(kcglService.updateHotelInventory(hotelInventory));
    }

    /**
     * 新物料入库
     */
    @RequiresPermissions("system:kcgl:addx")
    @GetMapping("/addx")
    public String addx()
    {
        return prefix + "/addx";
    }

    /**
     * 新增保存岗位
     */
    @RequiresPermissions("system:kcgl:add")
    @Log(title = "新物料入库", businessType = BusinessType.INSERT)
    @PostMapping("/addSave")
    @ResponseBody
    public AjaxResult addSave(@Validated HotelInventory HotelInventory)
    {
        kcglService.insertHotelInventory(HotelInventory);
        kcglService.insertHotelInventoryLog(HotelInventory);
        return toAjax(1);
    }


    /**
     * 库存调整记录页面
     */
    @GetMapping("/kctzjl")
    public String kctzjl()
    {
        return prefix + "/kctzjl";
    }

    @PostMapping("/kctzjlList")
    @ResponseBody
    public TableDataInfo kctzjlList(HotelInventoryLog hotelInventoryLog)
    {

        startPage();
        List<HotelInventoryLog> list = kcglService.selectInventoryLogList(hotelInventoryLog);
        return getDataTable(list);
    }

    @Log(title = "库存管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(HotelInventory post)
    {
        List<HotelInventory> list = kcglService.selectInventoryList(post);
        ExcelUtil<HotelInventory> util = new ExcelUtil<HotelInventory>(HotelInventory.class);
        return util.exportExcel(list, "岗位数据");
    }





}
